package cn.bonoon.kernel.io;

import java.io.File;

import javax.servlet.ServletContext;

public class FileInfo extends SimpleFileInfo{
	
	final String originalFilename;
	
	FileInfo(String originalFilename){
		this.originalFilename = originalFilename;
		int p = originalFilename.lastIndexOf('.');
		if(p > 0){
			filename = originalFilename.substring(0, p);
			filesuffix = originalFilename.substring(p);//后缀带'.'
		}else{
			filename = originalFilename;
			filesuffix = "";//没有定义后缀的情况
		}
	}
	
	

	long size;

	boolean savePath(ServletContext servletContext, String relativePath, String filename){
		this.filename = filename;
		return savePath(servletContext, relativePath);
	}
	
	boolean savePath(ServletContext servletContext, String relativePath){
		this.relativePath = relativePath + filename + filesuffix;
		this.absolutePath = servletContext.getRealPath(this.relativePath);
		this.file = new File(this.absolutePath);
		return file.exists();
	}

	String name;
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}


	public String getOriginalFilename() {
		return originalFilename;
	}
}
